package com.daxue.se.juc.day01;

import java.util.concurrent.*;

/**
 * @author daxue0929
 * @date 2022/9/14
 */

public class CompletableFuturePoolDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        long startTime = System.currentTimeMillis();
        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        FutureTask<String> futureTask1 = new FutureTask<>(() -> {
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "task1";
        });
        threadPool.execute(futureTask1);

//        FutureTask<String> futureTask2 = new FutureTask<>(() -> {
//            try {TimeUnit.MILLISECONDS.sleep(300);} catch (InterruptedException e) {e.printStackTrace();}
//            return "task2";
//        });
//        threadPool.execute(futureTask2);
//
//
//        try {TimeUnit.MILLISECONDS.sleep(200);} catch (InterruptedException e) {e.printStackTrace();}
//        System.out.println(futureTask1.get());
//        System.out.println(futureTask2.get());
//
//        long endTime = System.currentTimeMillis();
//
//        System.out.println("----costTime: " + (endTime - startTime) + " 毫秒");
        System.out.println(Thread.currentThread().getName() + "\t ----end");

    }
}






